"use strict";

/**
 * author:Administrator
 * date:2015/11/30
 * desc: user face dao
 */
var Model = require('../model/face_user.js');
var dao = {};
var counter = require('./counter.js');
var myCounter = counter.bindCounter(counter.TypesEnum.faceUser);
module.exports = dao;

/**
 * save
 * @param json {object}
 */
dao.save = function *(json) {
  var ufaceid = yield myCounter();
  var entity = new Model({
    uid: json.uid,
    ufaceid: ufaceid,
    path: json.path,
    rpath: json.rpath
  });

  return yield entity.save();
};

dao.getOneById = function*(ufaceid) {
  return yield Model.findOne({ufaceid: ufaceid});
};

dao.updateFeatures = function * (ufaceid, features) {
  return yield Model.update({ufaceid: ufaceid}, {$set: {features: features}});
};

dao.cleanCollection = function*() {
  return yield Model.remove({});
};